﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Mvc;


namespace System.Web.Mvc
{
	public static class MobileViewHelperExtensions
	{

		public static void DesktopView(this HtmlHelper html, Action<HtmlHelper> lambda)
		{
			if (!html.ViewContext.HttpContext.Request.IsMobileDeviceRequest())
			{
				string text = lambda.DynamicInvoke(html).ToString();
				using (var writer = new HtmlTextWriter(html.ViewContext.Writer))
					writer.Write(text);
			}
		}

		public static IHtmlString DesktopView(this HtmlHelper html, Func<HtmlHelper, IHtmlString> lambda)
		{
			if (!html.ViewContext.HttpContext.Request.IsMobileDeviceRequest())
			{
				return lambda(html);
			}
			else
				return new MvcHtmlString("");
		}

		public static void MobileView(this HtmlHelper html, Action<HtmlHelper> lambda)
		{
			if (html.ViewContext.HttpContext.Request.IsMobileDeviceRequest())
			{
				string text = lambda.DynamicInvoke(html).ToString();
				using (var writer = new HtmlTextWriter(html.ViewContext.Writer))
					writer.Write(text);
			}
		}

		public static IHtmlString MobileView(this HtmlHelper html, Func<HtmlHelper, IHtmlString> lambda)
		{
			if (html.ViewContext.HttpContext.Request.IsMobileDeviceRequest())
			{
				return lambda(html);
			}
			else
				return new MvcHtmlString("");
		}

	}
}
